package cn.sunshine.org.controller;

import cn.sunshine.basic.annotation.PreAuthorize;
import cn.sunshine.org.service.IShopAuditLogService;
import cn.sunshine.org.domain.ShopAuditLog;
import cn.sunshine.org.query.ShopAuditLogQuery;
import cn.sunshine.basic.utils.AjaxResult;
import cn.sunshine.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shopAuditLog")
public class ShopAuditLogController {
    @Autowired
    public IShopAuditLogService shopAuditLogService;


    /**
     * 保存和修改公用的
     * @param shopAuditLog  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    @PreAuthorize(name = "新增或者修改日志" ,sn = "shopAuditLog:addOrUpdate")
    public AjaxResult addOrUpdate(@RequestBody ShopAuditLog shopAuditLog){
        try {
            if( shopAuditLog.getId()!=null)
                shopAuditLogService.update(shopAuditLog);
            else
                shopAuditLogService.save(shopAuditLog);
            return AjaxResult.getAjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult().setMessage("保存对象失败！"+e.getMessage());
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    @PreAuthorize(name = "删除日志",sn = "shopAuditLog:remove")
    public AjaxResult remove(@PathVariable("id") Long id){
        try {
            shopAuditLogService.remove(id);
            return AjaxResult.getAjaxResult();
        } catch (Exception e) {
        e.printStackTrace();
            return AjaxResult.getAjaxResult().setMessage("删除对象失败！"+e.getMessage());
        }
    }
	
    //获取用户
    @GetMapping("/{id}")
    @PreAuthorize(name = "根据Id查询",sn = "shopAuditLog:get")
    public ShopAuditLog get(@PathVariable("id")Long id)
    {
        return shopAuditLogService.loadById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    @PreAuthorize(name = "查询所有",sn = "shopAuditLog:loadAll")
    public List<ShopAuditLog> loadAll(){

        return shopAuditLogService.loadAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    @PreAuthorize(name = "高级查询查询所有",sn = "shopAuditLog:queryData")
    public PageList<ShopAuditLog> queryData(@RequestBody ShopAuditLogQuery query)
    {
        return shopAuditLogService.queryData(query);
    }
    @PatchMapping
    @PreAuthorize(name = "批量删除日志数据",sn = "shopAuditLog:batchRemove")
    public AjaxResult batchRemove(@RequestBody List<Long> ids){
        try {// 调用删除方法，根据id删除
                shopAuditLogService.batchRemove( ids);
            return AjaxResult.getAjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult().setSuccess(false).setMessage("系统繁忙，请重试");

        }
    }
}
